package com.ibm.epss.android;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class PackageExpressNotificationActivity extends Activity implements OnClickListener {
    //private TextView tvMsg;
    private ActivityProfile activityProfile = ActivityProfile.getInstance();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.showmsg);

        // Init button for go_back to main activity and clear_msg
        Button btnBack = (Button) findViewById(R.id.btnBack);
        Button btnClear = (Button) findViewById(R.id.btnClear);
        btnBack.setOnClickListener(this);
        btnClear.setOnClickListener(this);

        // Print all received msg on screen
        activityProfile.setTvMsg((TextView) findViewById(R.id.tvMsg));
        for (String strMsg : activityProfile.getReceivedMsgs()) {
            activityProfile.getTvMsg().append(strMsg + "\n");
        }
    }

    @Override
    protected void onStart() {
        // Reset notification number & remove notification
        if (null != activityProfile.getNotification()
                && null != activityProfile.getNotiMgr()) {
            activityProfile.getNotification().number = 0;
            activityProfile.getNotiMgr().cancel(activityProfile.getNotificationID());
        }
        super.onStart();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btnBack:
                this.onBackPressed();
                break;
            case R.id.btnClear:
                activityProfile.getTvMsg().setText(R.string.received_msgs);
                activityProfile.getReceivedMsgs().clear();
                break;
        }
    }

    @Override
    public void onBackPressed() {
        Intent intent = new Intent();
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.setClass(this, PackageExpressActivity.class);
        startActivity(intent);
        this.finish();
        super.onBackPressed();
    }

}
